package com.niodata.dp.core.context;

import com.niodata.dp.core.usermgr.model.UserInfo;

public class SimpleUserInfoAware implements UserInfoAware {

  private static final ThreadLocal<Context> contextThreadLocal = new InheritableThreadLocal();

  public static void setContext(Context context) {
    contextThreadLocal.set(context);
  }

  public static void cleanContext() {
    contextThreadLocal.remove();
  }

  @Override
  public UserInfo getCurrentUser() {
    Context context =
          ContextProvider.context() == null ? contextThreadLocal.get() : ContextProvider.context();
    return context == null ? null : context.currentUser();
  }
}
